package com.example.application.activity;

import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.application.MyBroadcastReceiver;
import com.example.application.R;

public class MainActivity1 extends AppCompatActivity {
    private MyBroadcastReceiver myReceiver = new MyBroadcastReceiver();
    private boolean mRegistered = false;

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findViewById(R.id.button_register).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IntentFilter intentFilter = new IntentFilter();
                intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
                intentFilter.addAction(Intent.ACTION_SCREEN_ON);
                intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
                intentFilter.addAction(Intent.ACTION_USER_PRESENT);
                intentFilter.addAction(Intent.ACTION_BATTERY_OKAY);
                intentFilter.addAction(Intent.ACTION_BATTERY_LOW);
                intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
                //intentFilter.addAction("com.vt.c0701.MyBroadcastReceiver.ss");
                registerReceiver(myReceiver, intentFilter);
                mRegistered = true;
            }
        });
        findViewById(R.id.button_register).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mRegistered) {
                    unregisterReceiver(myReceiver);
                    mRegistered = false;
                }
            }

            private void unregisterReceiver(MyBroadcastReceiver myReceiver) {
            }
        });
        findViewById(R.id.button_start_activity).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Intent i = new Intent(MainActivity.class, );
                //startActivity(i);
            }
        });

    }

}
